<!DOCTYPE html>
<html lang="zh">
<head>
<base href="/">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>首页 - 光年(Light Year Admin)后台管理系统模板</title>
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link href="css/materialdesignicons.min.css" rel="stylesheet">
  <link href="css/style.min.css" rel="stylesheet">
  <link href="css/animate.css" rel="stylesheet">
  <!--对话框-->
  <link rel="stylesheet" href="js/jconfirm/jquery-confirm.min.css">
  <link rel="stylesheet" href="css/bootstrapValidator.css"/>
</head>
  
<body data-logobg="color_8" data-headerbg="color_8" data-sidebarbg="color_8" data-theme="default" >
<div class="lyear-layout-web">
  <div class="lyear-layout-container">

    <div id="common" >
      <!--左侧导航-->
      <aside class="lyear-layout-sidebar">

        <!-- logo -->
        <div id="logo" class="sidebar-header">
          <a href="api/index.jsp"><img src="/images/logo-zl.png" title="LightYear" alt="LightYear" /></a>
        </div>
        <div class="lyear-layout-sidebar-scroll">

          <nav class="sidebar-main">
            <ul class="nav nav-drawer">
              <li class="nav-item "> <a href="/api/index.html"><i class="mdi mdi-home"></i> 后台首页</a></li>
              <li class="nav-item "> <a href="/api/user.html"><i class="mdi mdi-account-multiple"></i> 用户管理</a></li>
              <li class="nav-item "> <a href="/api/novel.html"><i class="mdi mdi-book-open-page-variant"></i> 小说管理</a></li>
              <li class="nav-item "> <a href="/api/category.html"><i class="mdi mdi-server"></i> 类别管理</a></li>
              <li class="nav-item "> <a href="/api/admin.html"><i class="mdi mdi-account-multiple"></i> 管理员管理</a></li>
              <li class="nav-item nav-item-has-subnav">
            </ul>
          </nav>

        </div>

      </aside>
      <!--End 左侧导航-->

      <!--头部信息-->
      <header class="lyear-layout-header">

        <nav class="navbar navbar-default">
          <div class="topbar">

            <div class="topbar-left">
              <div class="lyear-aside-toggler">
                <span class="lyear-toggler-bar"></span>
                <span class="lyear-toggler-bar"></span>
                <span class="lyear-toggler-bar"></span>
              </div>
              <span class="navbar-page-title">  </span>
            </div>

            <ul class="topbar-right">
              <li class="dropdown dropdown-profile">
                <a href="javascript:void(0)" data-toggle="dropdown">

                  <span><span id="name"></span><span class="caret" ></span></span>
                </a>
                <ul class="dropdown-menu dropdown-menu-right">
                  <li> <a href="javascript:void(0)" id="getAdmin" ><i class="mdi mdi-account"></i> 个人信息</a> </li>
                  <li> <a href="javascript:void(0)" id="updateAdmin"><i class="mdi mdi-lock-outline"></i> 修改密码</a> </li>
                  <li class="divider"></li>
                  <li> <a href="javascript:void(0)" id="exit" ><i class="mdi mdi-logout-variant"></i> 退出登录</a> </li>
                </ul>
              </li>
            </ul>

          </div>
        </nav>

      </header>
      <!--End 头部信息-->

      <!--个人信息-->
      <div class="modal fade" id="admin-class" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" >个人信息</h4>
            </div>
            <div class="modal-body">
              <form class="form-horizontal"  action="lyear_forms_elements.html" method="post" onsubmit="return false;">
                <div class="form-group">
                  <label class="col-md-3 control-label" for="adminid">账号：</label>
                  <div class="col-md-7">
                    <input class="form-control" type="text" readonly id="adminid"  >
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-md-3 control-label" for="adminusername">账号：</label>
                  <div class="col-md-7">
                    <input class="form-control" type="text" readonly id="adminusername" >
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-md-3 control-label"  for="adminpassword">密码：</label>
                  <div class="col-md-7">
                    <input class="form-control" type="text" readonly id="adminpassword" >
                  </div>
                </div>
              </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
          </div>
        </div>
      </div>
      <!--个人信息end-->

      <!--修改密码-->
      <div class="modal fade" id="password-class" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="clearForm()"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" >个人信息</h4>
            </div>
            <div class="modal-body">
              <form class="form-horizontal"  action="lyear_forms_elements.html" id="updateForm" method="post" onsubmit="return false;">
                <div class="form-group">
                  <label class="col-md-3 control-label" for="oldpassword" >旧密码：</label>
                  <div class="col-md-7">
                    <input class="form-control" type="password" id="oldpassword" name="oldpassword" placeholder="请输入旧密码">
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-md-3 control-label" for="newpassword1" >新密码：</label>
                  <div class="col-md-7">
                    <input class="form-control" type="password" id="newpassword1" name="newpassword1" placeholder="请输入新密码">
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-md-3 control-label" for="newpassword2" placeholder="请输入再次输入新密码">新密码：</label>
                  <div class="col-md-7">
                    <input class="form-control" type="password" id="newpassword2" name="newpassword2" placeholder="请输入再次输入新密码">
                  </div>
                </div>
              </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal" onclick="clearForm()">关闭</button>
              <button type="button" class="btn btn-primary" id="update">修改</button>
            </div>
          </div>
        </div>
      </div>
      <!--修改密码end-->
    </div>


    <!--页面主要内容-->
    <main class="lyear-layout-content">
      <div class="container-fluid">

        <div class="row">
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-primary">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">今日收入</p>
                  <p class="h3 text-white m-b-0 fa-1-5x">102,125.00</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-currency-cny fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>

          <div class="col-sm-6 col-lg-3">
            <div class="card bg-danger">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">用户总数</p>
                  <p class="h3 text-white m-b-0 fa-1-5x">920,000</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-account fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>

          <div class="col-sm-6 col-lg-3">
            <div class="card bg-success">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">下载总量</p>
                  <p class="h3 text-white m-b-0 fa-1-5x">34,005,000</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-arrow-down-bold fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>

          <div class="col-sm-6 col-lg-3">
            <div class="card bg-purple">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">新增留言</p>
                  <p class="h3 text-white m-b-0 fa-1-5x">153 条</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-comment-outline fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
        </div>

        <div class="row">

          <div class="col-lg-12">
            <div class="card" style="width: 100%">
              <div class="card-body">
                <div id="user" style="width: 800px;height:400px;"></div>
                <div id="category" style="width: 600px;height:400px;"></div>
              </div>
            </div>
          </div>



        </div>

      </div>
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>
<script src="js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="js/template-web.js"></script>
<script type="text/javascript" src="js/lightyear.js"></script>
<!--对话框-->
<script src="js/jconfirm/jquery-confirm.min.js"></script>
<!--图表插件-->
<script src="js/echarts.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>
<script src="api/echarts"></script>
<script type="text/javascript">
$(document).ready(function(e) {
  $.ajax({
    url:"api/index/option1",
    type:"GET",
    dataType:"JSON",
    success:function (resp){
      if(resp.code===10000){
        // 基于准备好的dom，初始化echarts实例
        var myChart1 = echarts.init(document.getElementById('user'),'macarons');

        // 指定图表的配置项和数据
        var option1 = {
          title: {
            text: '用户小说数'
          },
          tooltip: {},
          legend: {
            data: ['小说数量']
          },
          xAxis: {
            data: resp.data.username,
            axisLabel:{
            }
          },
          yAxis: {},
          grid: {
            containLabel: true // 使柱状图宽度自适应
          },
          series: [
            {
              name: '小说数量',
              type: 'bar',
              data: resp.data.novelcount
            }
          ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart1.setOption(option1);
      }else {
        lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center' );
      }
    }
  })


  $.ajax({
    url:"api/index/option2",
    type:"GET",
    dataType:"JSON",
    success:function (resp){
      if(resp.code===10000){
        var myChart2 = echarts.init(document.getElementById('category'));
        var option2;

        option2 = {
          title: {
            text: '小说类别',
            left: 'center'
          },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: 'Access From',
              type: 'pie',
              radius: '50%',
              data: resp.data,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        };

        myChart2.setOption(option2);
      }else {
        lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center' );
      }
    }
  })

  function clearForm(){
    $("#updateForm").data('bootstrapValidator').resetForm(true);
    $("#oldpassword").val(null);
    $("#newpassword1").val(null);
    $("#newpassword2").val(null);
  }

  $("#exit").click(function (){
    $.confirm({
      title: '退出登录',
      content: '确定退出登录该账号',
      buttons: {
        confirm: {
          text: '确认',
          action: function(){
            $.ajax({
              url:"logout",
              type:"POST",
              dataType:"JSON",
              success:function (resp){
                if(resp.code===10000){
                  lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center','${pageContext.request.contextPath}/login.jsp' );
                }else {
                  lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center' );
                }
              }
            })
          }
        },
        cancel: {
          text: '取消',
        },
      }
    });
  })

  $("#getAdmin").click(function (){
    $("#admin-class").modal("show");
    getAdmin();
  })

  $("#updateAdmin").click(function (){
    $("#password-class").modal("show");
  })

  $("#update").click(function (){
    $("#updateForm").data('bootstrapValidator').validate();//相当于触发一次所有的验证
    if($("#updateForm").data('bootstrapValidator').isValid()){//判断验证是否已经通过
      $.ajax({
        url:"api/common/update",
        type:"POST",
        data:{newPassword:$("#newpassword1").val(),oldPassword:$("#oldpassword").val()},
        dataType:"JSON",
        success:function (resp){
          if(resp.code===10000){
            $("#password-class").modal('hide');
            clearForm();
            lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center');
          }else {
            clearForm();
            lightyear.notify(resp.msg, 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center' );
          }
        }
      })
    }
  })

  $(document).ready(function () {
    getAdmin();
  });
  function getAdmin(){
    $.ajax({
      url:"api/common/get",
      type:"GET",
      dataType:"JSON",
      success:function (resp){
        if(resp.code===10000){
          $("#name").text(resp.data.username);
          $("#adminid").val(resp.data.id);
          $("#adminusername").val(resp.data.username);
          $("#adminpassword").val(resp.data.password);
        }else {
        }
      }
    })
  }

  /**
   *下面就是bootstrapValidator的初始化
   *定义你需要的哪些表单需要验证，验证什么内容
   **/
  $("#updateForm").bootstrapValidator({
    feedbackIcons: {//这里是用来对应三种不同状态时，在输入框后面添加的图标
      valid: 'glyphicon glyphicon-ok',
      invalid: 'glyphicon glyphicon-remove',
      validating: 'glyphicon glyphicon-refresh'
    },
    fields:{//哪些字段需要验证，和html中的输入框，下拉框等等表单name属性所对应。
      oldpassword:{
        validators:{//从这里也可以容易的看出可以有多个验证信息
          notEmpty:{//非空验证
            message:"请输入旧密码！！！" //提示信息，当你不写这里时它会自动的调用自带的提示信息，默认是英文，可导入language下的中文JS文件
          },
        }
      },
      newpassword1:{
        validators:{
          notEmpty:{
            message:"请输入新密码！！！"
          }
        }
      },
      newpassword2:{
        validators:{
          notEmpty:{
            message:"请输入验证码！！！"
          },
          identical: {//用来判断制定的字段和当前字段一致与否
            field: 'newpassword1',
            message: "两次输入的密码不一致！！！"
          }

        }
      }
    }
  });

});
</script>
</body>
</html>